﻿using System;
using System.IO;
using System.Text;

namespace _88W
{
    static class Program
    {
        static void Main(string[] args)
        {
            #region 运行88万行代码
            //var numberchar = Console.ReadLine();
            //int number = int.Parse(numberchar);
            //_88WCode.RunNumber(number);
            #endregion

            #region 生成88万行代码
            //Code();
            #endregion
        }

        static void Code()
        {
            StringBuilder sb = new StringBuilder(100);
            sb.Append("switch (number){").Append(Environment.NewLine);
            for (int i = 1; i <= 99999; i++)
            {
                string number = i.ToString();
                sb.Append($"case {i}:{Environment.NewLine}Console.WriteLine(\"是{number.Length}位数\");").Append(Environment.NewLine);
                for (int j = 0; j < number.Length; j++)
                {
                    switch (j)
                    {
                        case 0:
                            sb.Append($"Console.WriteLine(\"个位数是{number[number.Length - 1 - j]}\");" + Environment.NewLine);
                            break;
                        case 1:
                            sb.Append($"Console.WriteLine(\"十位数是{number[number.Length - 1 - j]}\");").Append(Environment.NewLine);
                            break;
                        case 2:
                            sb.Append($"Console.WriteLine(\"百位数是{number[number.Length - 1 - j]}\");").Append(Environment.NewLine);
                            break;
                        case 3:
                            sb.Append($"Console.WriteLine(\"千位数是{number[number.Length - 1 - j]}\");").Append(Environment.NewLine);
                            break;
                        case 4:
                            sb.Append($"Console.WriteLine(\"万位数是{number[number.Length - 1 - j]}\");").Append(Environment.NewLine);
                            break;
                        default:
                            break;
                    }
                }
                sb.Append($"Console.WriteLine(\"倒过来是{number.Reverse()}\");").Append(Environment.NewLine);
                sb.Append("break;").Append(Environment.NewLine);
            }
            sb.Append("}");
            CreateTxt(sb.ToString());
        }

        static string Reverse(this string sb)
        {
            StringBuilder resb = new(sb.Length);
            for (int i = 0; i < sb.Length; i++)
            {
                resb.Append(sb[sb.Length - 1 - i]);
            }
            return resb.ToString();
        }

        static void CreateTxt(string text)
        {
            using StreamWriter sw = new("code.txt");
            sw.WriteLine(text);
        }
    }
}
